﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;
using EPPLib.Domain.Messages;

namespace EPPLib.Managers
{
    public abstract class BaseManager
    {
        protected string Request(BaseRequest obj)
        {
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri("https://pub-test.nic.it"));
            request.Method = "POST";
            request.ContentType = "text/xml";

            // Serialize request
            StreamWriter sw = new StreamWriter(request.GetRequestStream());
            sw.Write(obj.Serialize().ToString());
            sw.Close();

            // Read response
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            StreamReader sr = new StreamReader(response.GetResponseStream());
            string responseData = sr.ReadToEnd();

            sr.Close();
            response.Close();

            return responseData;
        }
    }
}
